package src.montecarlo;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import src.utils.NormalFunction;
import src.utils.ProbabilityDistributionFunction;

public class AvoidingAutoCorrelation {

	public static void main(String[] argvs) throws IOException{
		
		int sampleSize;
		
		double deltaMin;
		double deltaMax;
		double eps;
		
		String outputFile;
		
		try {
			sampleSize = new Integer(argvs[0]);
			deltaMin = new Double(argvs[1]);
			deltaMax = new Double(argvs[2]);
			eps = new Double(argvs[3]);
			
			outputFile = argvs[4];
			
		} catch (Exception e) {
			showUsage();
			return;
		}
		
		double mean = 0; double sigma = 1;
		ProbabilityDistributionFunction pdf = new NormalFunction(mean,sigma);
		
		FileOutputStream fos = new FileOutputStream(new File("output.dat"));
		
		for(double delta = deltaMin;delta<deltaMax;delta+=eps){
			
			
			MetropolisMonteCarlo simulator =  new MetropolisMonteCarlo(pdf,sampleSize,delta,0);
			String sampledNumber = (new Integer((int)Math.floor(delta*100)).toString());
			simulator.metropolisAlgorithm(outputFile+sampledNumber);
			simulator.reSample(50,sampledNumber);
			fos.write((delta+","+outputFile+sampledNumber+","+sampledNumber+"\n").getBytes());
		}
	}
	
	private static void showUsage() {
		
		System.out.println("Usage: ");	
		System.out.println("<sampleSize> <delta> <step> <outputFile>\n");
		
		System.out.println("<sampleSizew>: Size of the sample.");
		System.out.println("<delta>: step to explore when creating the distribution.");
		System.out.println("<step>: number(integer) to jump between sampling rates.");
		System.out.println("<outputFile>: where to save the results.");
	}
}
